package org.wdcode.back.tag.button;

import java.io.IOException;

import javax.servlet.jsp.JspException;

import org.wdcode.back.tag.ui.HiddenTag;
import org.wdcode.back.tag.ui.PasswordTag;
import org.wdcode.common.log.WdLogs;

/**
 * @author WD
 * @since JDK6
 * @version 1.0 2010-3-24
 */
public final class ResetPwdTag extends SubmitTag {
	// 序列化ID
	private static final long	serialVersionUID	= 7762268150051912464L;

	// 显示按钮
	private SubmitTag			show;
	// 密码框
	private PasswordTag			password;
	// 隐藏框
	private HiddenTag			hidden;
	// 提交按钮
	private SubmitTag			submit;

	/**
	 * 标签结束
	 */
	@Override
	public int doEndTag() throws JspException {
		try {
			show.doStartTag();
			show.doEndTag();
			pageContext.getOut().write("<div id='hide' class='hide'>");
			password.doStartTag();
			password.doEndTag();
			hidden.doStartTag();
			hidden.doEndTag();
			submit.doStartTag();
			submit.doEndTag();
			pageContext.getOut().write("</div>");
		} catch (IOException e) {
			WdLogs.error(e);
		}
		return EVAL_PAGE;
	}

	/**
	 * 标签开始
	 */
	@Override
	public int doStartTag() throws JspException {
		// 初始化
		init();
		// 标签开始
		return SKIP_BODY;
	}

	/**
	 * 初始化
	 */
	private void init() {
		// 显示按钮
		show = new SubmitTag();
		show.setPageContext(pageContext);
		show.setId("show");
		show.setCssClass("submit");
		show.setValue("%{getText('reset')+getText('pwd')}");

		// 密码框
		password = new PasswordTag();
		password.setPageContext(pageContext);
		password.setCssClass("text");
		password.setName("newPwd");

		// 隐藏框
		hidden = new HiddenTag();
		hidden.setPageContext(pageContext);
		hidden.setName("oldPwd");
		hidden.setValue("%{#request.entity.password}");

		// 提交按钮
		submit = new SubmitTag();
		submit.setPageContext(pageContext);
		submit.setAction("resetPwd");
		submit.setCssClass("submit");
		submit.setValue("%{getText('ok')}");
	}
}
